"""
医生数据模型
"""
from sqlalchemy import Column, Integer, String, SmallInteger, DateTime
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship

from  core.database import Base


class Doctor(Base):
    """医生表"""
    __tablename__ = "doctors"
    
    id = Column(Integer, primary_key=True, index=True, comment="医生ID")
    name = Column(String(100), nullable=False, comment="医生姓名")
    # 使用普通字符串类型存储性别（"男" 或 "女"）
    gender = Column(String(10), nullable=True, comment="性别")
    phone = Column(String(20), nullable=False, unique=True, index=True, comment="手机号")
    password_hash = Column(String(255), nullable=False, comment="密码哈希")
    title = Column(String(100), nullable=True, comment="职称")
    status = Column(SmallInteger, nullable=False, default=1, comment="状态 1-正常 0-禁用")
    created_at = Column(
        DateTime(timezone=True), 
        nullable=False, 
        server_default=func.now(),
        comment="创建时间"
    )
    updated_at = Column(
        DateTime(timezone=True),
        nullable=False,
        server_default=func.now(),
        onupdate=func.now(),
        comment="更新时间"
    )
    
    # 关系
    patients = relationship("Patient", back_populates="doctor")
    templates = relationship("Template", back_populates="creator")
    
    def __repr__(self):
        return f"<Doctor(id={self.id}, name={self.name}, phone={self.phone})>"

